import React, { Component } from 'react'
import Catelist from 'components/catelist/Catelist'

export default class Material extends Component {

  constructor() {
    super();
    this.state = {
      nav: ''
    }
  }

  changeNav(nav) {
    this.setState({
      nav
    })
  }

  static getDerivedStateFromProps(props,state) {
    if(state.nav){
      return null
    }else if(props.list){
      //第一次加载数据时用到
      return {
        nav: Object.keys(props.list)[0]
      }
    }
    return null
  }

  render() {
    return (
      <div>
        <Catelist {...this.props} nav={this.state.nav}
          change={(nav) => {
            this.changeNav(nav)
          }}
        ></Catelist>
      </div>
    )
  }
  componentDidMount() {
    console.log(this.props)
  }
}
